package com.hd.determine.modules.vehicle.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 车辆末次信息表 | 看看pg有没有内存表
 * </p>
 *
 * @author chentl123
 * @since 2020-12-28
 */
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sp_vehicle_end_pos")
public class VehicleEndPos extends Model<VehicleEndPos> implements Serializable {

    private static final long serialVersionUID = 1L;

    //GPS坐标查询构造
    public VehicleEndPos(String regionCode, Integer length) {
        this.regionCode = regionCode;
        this.length = length;
    }


    //实时监测查询构造
    public VehicleEndPos(String platNo, String platNoColor, String enterpriseNo) {
        this.platNo = platNo;
        this.platNoColor = platNoColor;
        this.enterpriseNo = enterpriseNo;
    }

    //驾驶员信息构造
    public VehicleEndPos(String platNo, String platNoColor, String driverName, String enterpriseNo) {
        this.platNo = platNo;
        this.platNoColor = platNoColor;
        this.driverName = driverName;
        this.enterpriseNo = enterpriseNo;
    }

    //插入构造
    public VehicleEndPos(Long vehicleStatus, Double lng, Double lat, Double speed, Double alt, Date gpsTime, Double direction, Long alarmType, Double addSpeed, String platNo, String platNoColor, Integer onlineStatus, String vehicleType, String transType, String regionCode, String regionName, String enterpriseName, String enterpriseNo, String vehicleId, String deptId) {
        this.vehicleStatus = vehicleStatus;
        this.lng = lng;
        this.lat = lat;
        this.speed = speed;
        this.alt = alt;
        this.gpsTime = gpsTime;
        this.createTime = new Date();
        this.direction = direction;
        this.alarmType = alarmType;
        this.addSpeed = addSpeed;
        this.platNo = platNo;
        this.platNoColor = platNoColor;
        this.onlineStatus = onlineStatus;
        //持久化数据
        this.vehicleType = vehicleType;
        this.transType = transType;
        this.regionCode = regionCode;
        this.regionName = regionName;
        this.enterpriseName = enterpriseName;
        this.enterpriseNo = enterpriseNo;
        this.vehicleId = vehicleId;
        this.deptId = deptId;
    }

    /**
     * 末次信息id
     */
    private String id;
    /**
     * 车辆状态 |  整数存二进制  aac 开、aac关等..
     */
    @TableField("vehicle_status")
    private Long vehicleStatus;
    /**
     * 经度
     */
    private Double lng;
    /**
     * 维度
     */
    private Double lat;
    /**
     * 速度
     */
    private Double speed;
    /**
     * 高度
     */
    private Double alt;
    /**
     * GPS时间
     */
    @TableField("gps_time")
    private Date gpsTime;
    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;
    /**
     * 方向
     */
    private Double direction;
    /**
     * 报警类型 | 整数存二进制
     */
    @TableField("alarm_type")
    private Long alarmType;
    /**
     * 附加信息
     */
    @TableField("info_ex")
    private String infoEx;
    /**
     * 行车记录仪速度
     */
    @TableField("add_speed")
    private Double addSpeed;
    /**
     * 车牌号
     */
    @TableField("plat_no")
    private String platNo;
    /**
     * 车牌颜色
     */
    @TableField("plat_no_color")
    private String platNoColor;
    /**
     * 连续驾驶开始时间
     */
    @TableField("continuous_driving_start_time")
    private Date continuousDrivingStartTime;
    /**
     * 数据更新时间
     */
    @TableField("update_time")
    private Date updateTime;
    /**
     * 停车时间
     */
    @TableField("parking_time")
    private Date parkingTime;
    /**
     * 连续驾驶时长
     */
    @TableField("driving_duration")
    private String drivingDuration;
    /**
     * 驾驶员姓名
     */
    @TableField("driver_name")
    private String driverName;
    /**
     * 车辆上线状态
     */
    @TableField("online_status")
    private Integer onlineStatus;
    /**
     * 静态数据同步状态 | 0 未同步 1 已同步
     */
    @TableField("static_data_status")
    private Integer staticDataStatus;
    /**
     * 同步描述
     */
    @TableField("sync_remark")
    private String syncRemark;
    /**
     * 组织机构id
     */
    @TableField("dept_id")
    private String deptId;

    /*****持久化数据 ******/
    @TableField(exist = false)
    private String vehicleType;

    @TableField(exist = false)
    private String transType;

    @TableField(exist = false)
    private String regionCode;

    @TableField(exist = false)
    private String regionName;

    @TableField(exist = false)
    private String enterpriseName;

    @TableField(exist = false)
    private String enterpriseNo;

    @TableField(exist = false)
    private String bizAlarmType;

    @TableField(exist = false)
    private String vehicleId;

    @TableField(exist = false)
    private Date lastGpsTime;

    @TableField(exist = false)
    private Date lastUpdateTime;

    @TableField(exist = false)
    private Double lastLng;

    @TableField(exist = false)
    private Double lastLat;

    @TableField(exist = false)
    private Integer length;

    @TableField(exist = false)
    private Date nightStartTime;

    @TableField(exist = false)
    private boolean scheduled;


    //地图视窗 左上 左下 右上 右下 经纬度
    @TableField(exist = false)
    private Double leftLng;
    @TableField(exist = false)
    private Double rightLng;
    @TableField(exist = false)
    private Double topLat;
    @TableField(exist = false)
    private Double bottomLat;

    /**
     * @return void
     * @author chentl
     * @description 清空GPS数据
     * @date 2021/1/7 3:48 下午
     * @params []
     */
    public void clearGpsData() {
        this.gpsTime = null;
        this.lng = null;
        this.lat = null;
        this.speed = null;
        this.alt = null;
        this.direction = null;
        this.addSpeed = null;
        this.continuousDrivingStartTime = null;
        this.lastUpdateTime = null;
        this.lastLng = null;
        this.lastLat = null;
    }

    /**
     * @return void
     * @author chentl
     * @description 清理夜间连续行驶时间
     * @date 2021/1/27 6:29 下午
     * @params []
     */
    public void clearNightStartTime() {
        this.nightStartTime = null;
    }


    /**
     * @return void
     * @author chentl
     * @description 刷新上次GPS
     * @date 2021/1/9 1:01 下午
     * @params []
     */
    public VehicleEndPos refreshLastGps() {
        this.lastGpsTime = this.gpsTime;
        this.lastUpdateTime = this.updateTime;
        this.lastLng = this.lng;
        this.lastLat = this.lat;
        return this;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
